package com.gem.mapper;

import com.gem.domain.CCrParticipant;
import com.gem.domain.CompanyContact;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Apolar_GuanYH-管阳红
 * Description: 参与人中间表映射
 * create 2019/10/30 14:05
 * Modified By:
 */
@Mapper
public interface CCrParticipantMapper {

    //查询所有
    @Select("SELECT * FROM c_cr_participant WHERE ccp_status>0")
    List<CCrParticipant> selectAllCP();

    //按编号查询
    @Select("SELECT * FROM c_cr_participant WHERE ccp_status>0 AND ccp_id=#{cpId}")
    CCrParticipant selectCPById(Integer cpId);

    //按企业-合作成果编号查询
    @Select("SELECT * FROM c_cr_participant WHERE ccp_status>0 AND ccp_cc_id=#{ccId}")
    List<CCrParticipant> selectCPByccId(Integer ccId);

    //按企业-合作成果编号查所有参与人
    @Select("SELECT ccp.ccp_id,con.* FROM company_contact con,c_cr_participant ccp WHERE co_contact_status>0 AND ccp_status>0 AND ccp.ccp_con_id=con.co_contact_id AND ccp_cc_id=#{ccId}")
    List<CompanyContact> selectConByccId(Integer ccId);

    //添加
    @Insert("INSERT INTO c_cr_participant(ccp_id,ccp_cc_id,ccp_con_id,ccp_remark) VALUES(#{ccpId},#{ccpCcId},#{ccpConId},#{ccpRemark})")
    boolean addCP(CCrParticipant cCrParticipant);

    //删除
    @Update("UPDATE c_cr_participant SET ccp_status=-1 WHERE ccp_id=#{cpId}")
    boolean deleteCP(Integer cpId);

}
